package com.bstu.ciit.lab3;

public class Field {
	private int length;
	private int width;
	private int food[]=new int[2];
	private int home[]=new int[2];
	private int wall[][]=new int[20][2];
	private int lake[][]=new int[20][2];
	public void lakeGener()
	{
		for (int i=0;i<20;i++)
		{
			lake[i][0]=i+20;
			lake[i][1]=i+49;
		}
	}
	public void wallGener()
	{
		for (int i=0;i<10;i++)
		{
			wall[i][1]=20;
			wall[i][0]=i+10;
		}
		for (int i=10;i<20;i++)
		{
			wall[i][0]=40;
			wall[i][1]=i-1;
		}
	}
	public boolean ofWall(int[] koord)
	{
		for(int i=0;i<20;i++)
			if(wall[i][0]==koord[0] && wall[i][1]==koord[1])
				return true;
		return false;
	}
	public boolean ofWater(int[] koord)
	{
		for(int i=0;i<20;i++)
			if(lake[i][0]==koord[0] && lake[i][1]==koord[1])
				return true;
		return false;
	}
	public Field(int length, int width)
	{
		this.length=length;
		this.width=width;
		home[0]=(int)(length/2);
		home[1]=(int)(width/2);
	}
	public Field(int length, int width, int homeLength, int homeWidth)
	{
		this.length=length;
		this.width=width;
		home[0]=homeLength;
		home[1]=homeWidth;
	}
	public int getLength() {
		return length;
	}
	public int getWidth() {
		return width;
	}
	public int[] getHome() {
		return home;
	}
	public void setFood(int length, int width)
	{
		food[0]=length;
		food[1]=width;
	}
	public int distance(int[] koord)
	{
		return Math.abs(koord[0]-food[0])+Math.abs(koord[1]-food[1]);
	}
	public void printField(int[] way)
	{
		char [][] field=new char[length][width];
		int[] step=new int[2];
		step[0]=home[0];
		step[1]=home[1];
		for(int i=0;i<length;i++)
		{
			for(int j=0;j<width;j++)
				field[i][j]='.';
		}
		for(int i=0;i<way.length;i++)
		{
			if (way[i]==0)
				step[1]-=1;
			if (way[i]==1)
				step[0]+=1;
			if (way[i]==2)
				step[1]+=1;
			if (way[i]==3)
				step[0]-=1;
			if (step[0]<0)
				step[0]+=length;
			if (step[1]<0)
				step[1]+=width;
			if (step[0]>=length)
				step[0]-=length;
			if (step[1]>=width)
				step[1]-=width;
			if (step[0]==food[0] && step[1]==food[1])
				break;
			field[step[0]][step[1]]='*';			
		}
		field[food[0]][food[1]]='8';
		field[this.home[0]][this.home[1]]='@';
		for(int i=0;i<wall.length;i++)
			field[wall[i][0]][wall[i][1]]='|';
		for(int i=0;i<lake.length;i++)
			field[lake[i][0]][lake[i][1]]='~';
		for(int i=0;i<length;i++)
		{
			for(int j=0;j<width;j++)
				System.out.print(field[i][j]);
			System.out.println();
		}
	}
	public int[] getFood() {
		return food;
	}
}
